<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="iOS中的常见的多线程方案">
<meta property="og:type" content="article">
<meta property="og:title" content="多线程">
<meta property="og:url" content="http://yoursite.com/2017/08/13/多线程/index.html">
<meta property="og:site_name" content="Erhqe">
<meta property="og:description" content="iOS中的常见的多线程方案">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006tNbRwly1fv7yxkwwcxj30n50betbq.jpg">
<meta property="og:updated_time" content="2019-07-19T05:40:06.065Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="多线程">
<meta name="twitter:description" content="iOS中的常见的多线程方案">
<meta name="twitter:image" content="https://ws1.sinaimg.cn/large/006tNbRwly1fv7yxkwwcxj30n50betbq.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/08/13/多线程/"/>





  <title>多线程 | Erhqe</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Erhqe</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/08/13/多线程/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Erhqe">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/10.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Erhqe">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">多线程</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-08-13T15:57:23+08:00">
                2017-08-13
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/多线程/" itemprop="url" rel="index">
                    <span itemprop="name">多线程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/08/13/多线程/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2017/08/13/多线程/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="iOS中的常见的多线程方案"><a href="#iOS中的常见的多线程方案" class="headerlink" title="iOS中的常见的多线程方案"></a>iOS中的常见的多线程方案<a id="more"></a></h4><p><img src="https://ws1.sinaimg.cn/large/006tNbRwly1fv7yxkwwcxj30n50betbq.jpg" alt=""></p>
<h5 id="GCD同步异步函数队列"><a href="#GCD同步异步函数队列" class="headerlink" title="GCD同步异步函数队列"></a>GCD同步异步函数队列</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">//	并发队列</span><br><span class="line">dispatch_queue_t queue = dispatch_get_global_queue(0, 0)</span><br><span class="line">dispatch_queue_t queue = dispatch_queue_create(&quot;name&quot;, DISPATCH_QUEUE_CONCURRENT);</span><br><span class="line">//	串行队列</span><br><span class="line">dispatch_queue_t queue = dispatch_queue_create(&quot;name&quot;, DISPATCH_QUEUE_SERIAL)</span><br><span class="line">    </span><br><span class="line">//	同步函数</span><br><span class="line">dispatch_sync( queue, ^&#123;</span><br><span class="line">        </span><br><span class="line">&#125;);</span><br><span class="line">//	异步函数			</span><br><span class="line">dispatch_async( queue, ^&#123;</span><br><span class="line">        </span><br><span class="line">    &#125;);</span><br></pre></td></tr></table></figure>
<h5 id="Swift"><a href="#Swift" class="headerlink" title="Swift"></a>Swift</h5><figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//	并发队列</span></span><br><span class="line"><span class="keyword">let</span> queue = <span class="type">DispatchQueue</span> (label: <span class="string">"name"</span>, qos: .<span class="keyword">default</span>, attributes: .concurrent, autoreleaseFrequency: .inherit, target: <span class="literal">nil</span>)</span><br><span class="line"><span class="comment">//	串行队列</span></span><br><span class="line"><span class="keyword">let</span> queue = <span class="type">DispatchQueue</span>(label: <span class="string">"name"</span>)</span><br><span class="line"></span><br><span class="line">queue.async &#123;</span><br><span class="line">            </span><br><span class="line">&#125;</span><br><span class="line">        </span><br><span class="line">queue.sync &#123;</span><br><span class="line">            </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 也可以一行代码</span></span><br><span class="line"><span class="type">DispatchQueue</span>.global().async &#123;</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line"><span class="type">DispatchQueue</span>.global().sync &#123;</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="type">DispatchQueue</span>(label: <span class="string">"name"</span>).sync &#123;</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// autoreleaseFrequency 自动释放频率</span></span><br><span class="line"><span class="comment">// qos 是优先级别  老版本GCD有四种 high，default，low，background</span></span><br><span class="line"><span class="comment">// 优先级为：high&gt;default&gt;low&gt;background</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 新版本GCD有六种 background，utility，default，userInitiated，userInteractive，unspecified</span></span><br><span class="line"><span class="comment">// 优先级为：userInteractive&gt;default&gt;unspecified&gt;userInitiated&gt;utility&gt;background</span></span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th style="text-align:center"></th>
<th style="text-align:center">并发队列</th>
<th style="text-align:center">手动创建的串行队列</th>
<th style="text-align:center">主队列</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">同步sync</td>
<td style="text-align:center">没有开启新线程<br>串行执行任务</td>
<td style="text-align:center">没有开启新线程<br>串行执行任务</td>
<td style="text-align:center">没有开启新线程<br>串行执行任务</td>
</tr>
<tr>
<td style="text-align:center">异步async</td>
<td style="text-align:center">有开启新线程<br>并发执行任务</td>
<td style="text-align:center">有开启新线程<br>串行执行任务</td>
<td style="text-align:center">没有开启新线程<br>串行执行任务</td>
</tr>
</tbody>
</table>
<h5 id="GCD死锁"><a href="#GCD死锁" class="headerlink" title="GCD死锁"></a>GCD死锁</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">// 会不会有线程死锁?  会</span><br><span class="line">// 队列的遵循 先进先出 FIFO</span><br><span class="line">// viewDidLoad就是主队列中的一个任务,也就是说遵循FIFO的话先执行完viewDidLoad之后才执行任务2,但是由于任务2是在当前线程执行,这样就会产生矛盾会线程死锁</span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    </span><br><span class="line">    NSLog(@&quot;任务1&quot;);</span><br><span class="line">    </span><br><span class="line">    dispatch_queue_t queue = dispatch_get_main_queue();</span><br><span class="line">    dispatch_sync(queue, ^&#123;</span><br><span class="line">        NSLog(@&quot;任务2&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">    </span><br><span class="line">    NSLog(@&quot;任务3&quot;);</span><br><span class="line">&#125;</span><br><span class="line">//	如果改成async 就不会产生死锁 顺序是132</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    </span><br><span class="line">    NSLog(@&quot;任务1&quot;);</span><br><span class="line">    </span><br><span class="line">    dispatch_queue_t queue = dispatch_queue_create(&quot;name&quot;, DISPATCH_QUEUE_SERIAL);</span><br><span class="line">    dispatch_async(queue, ^&#123;</span><br><span class="line">        </span><br><span class="line">        NSLog(@&quot;任务2&quot;);</span><br><span class="line">        </span><br><span class="line">        dispatch_sync(queue, ^&#123;	//Thread 4: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)</span><br><span class="line">            NSLog(@&quot;任务3&quot;);			</span><br><span class="line">        &#125;);</span><br><span class="line">        </span><br><span class="line">        NSLog(@&quot;任务4&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">    NSLog(@&quot;任务5&quot;);</span><br><span class="line">&#125;</span><br><span class="line">//打印结果 会死锁 </span><br><span class="line">2018-09-13 17:29:45.029842+0800 GCD笔记[13085:753477] 任务1</span><br><span class="line">2018-09-13 17:29:45.029994+0800 GCD笔记[13085:753477] 任务5</span><br><span class="line">2018-09-13 17:29:45.030015+0800 GCD笔记[13085:753588] 任务2</span><br><span class="line">//把队列改成并发队列就不会产生死锁</span><br><span class="line">dispatch_queue_t queue = dispatch_queue_create(&quot;name&quot;, DISPATCH_QUEUE_CONCURRENT);</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">//	不会死锁 因为任务3在 任务2执行后串行执行</span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    </span><br><span class="line">    NSLog(@&quot;任务1&quot;);</span><br><span class="line">    </span><br><span class="line">    dispatch_queue_t queue1 = dispatch_queue_create(&quot;name&quot;, DISPATCH_QUEUE_SERIAL);</span><br><span class="line">    dispatch_queue_t queue2 = dispatch_queue_create(&quot;name&quot;, DISPATCH_QUEUE_SERIAL);</span><br><span class="line">    dispatch_async(queue1, ^&#123;</span><br><span class="line">        </span><br><span class="line">        NSLog(@&quot;任务2&quot;);</span><br><span class="line">        </span><br><span class="line">        dispatch_sync(queue2, ^&#123;</span><br><span class="line">            NSLog(@&quot;任务3&quot;);</span><br><span class="line">        &#125;);</span><br><span class="line">        </span><br><span class="line">        NSLog(@&quot;任务4&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">    NSLog(@&quot;任务5&quot;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">//	会死锁 因为任务2在异步执行,但是里面有个同步任务3</span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    </span><br><span class="line">    NSLog(@&quot;任务1&quot;);</span><br><span class="line">    </span><br><span class="line">    dispatch_queue_t queue1 = dispatch_queue_create(&quot;name&quot;, DISPATCH_QUEUE_SERIAL);</span><br><span class="line">    dispatch_queue_t queue2 = dispatch_queue_create(&quot;name&quot;, DISPATCH_QUEUE_SERIAL);</span><br><span class="line">    dispatch_async(queue1, ^&#123;</span><br><span class="line">        </span><br><span class="line">        NSLog(@&quot;任务2&quot;);</span><br><span class="line">        </span><br><span class="line">        dispatch_sync(queue1, ^&#123;</span><br><span class="line">            NSLog(@&quot;任务3&quot;);</span><br><span class="line">        &#125;);</span><br><span class="line">        </span><br><span class="line">        NSLog(@&quot;任务4&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">    NSLog(@&quot;任务5&quot;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>规律 : 使用sync函数往<font color="red">当前</font><font color="blue">串行</font>队列中添加任务,会卡住当前的串行队列(产生死锁)</p>
</blockquote>
<h5 id="并发队列不同的方式创建是否是同一个"><a href="#并发队列不同的方式创建是否是同一个" class="headerlink" title="并发队列不同的方式创建是否是同一个?"></a>并发队列不同的方式创建是否是同一个?</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">dispatch_queue_t queue1 = dispatch_queue_create(&quot;queue1&quot;, DISPATCH_QUEUE_CONCURRENT);</span><br><span class="line">dispatch_queue_t queue2 = dispatch_queue_create(&quot;queue2&quot;, DISPATCH_QUEUE_CONCURRENT);</span><br><span class="line">dispatch_queue_t queue3 = dispatch_get_global_queue(0, 0);</span><br><span class="line">dispatch_queue_t queue4 = dispatch_get_global_queue(0, 0);</span><br><span class="line">NSLog(@&quot;%p ,%p ,%p,%p&quot;,queue1,queue2,queue3,queue4);</span><br><span class="line">//打印结果为 0x604000153cf0 ,0x604000153da0 ,0x10629e500,0x10629e500</span><br><span class="line">//手动创建的不一样 , 全局并发队列一样,跟全局变量类似 只有一份</span><br></pre></td></tr></table></figure>
<h5 id="GCD和Runloop相关的问题"><a href="#GCD和Runloop相关的问题" class="headerlink" title="GCD和Runloop相关的问题"></a>GCD和Runloop相关的问题</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event &#123;</span><br><span class="line">    </span><br><span class="line">    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);</span><br><span class="line">    dispatch_async(queue, ^&#123;</span><br><span class="line">        NSLog(@&quot;任务1&quot;);</span><br><span class="line">        [self performSelector:@selector(test) withObject:self afterDelay:.0];</span><br><span class="line">        NSLog(@&quot;任务3&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)test&#123;</span><br><span class="line">    NSLog(@&quot;任务2&quot;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 打印结果为</span><br><span class="line">19:58:28.104683+0800 XXX[14185:897666] 任务1</span><br><span class="line">19:58:28.104970+0800 XXX[14185:897666] 任务3</span><br><span class="line">//	没有打印 任务2 说明 [self performSelector:@selector(test) withObject:self afterDelay:.0]; 这行代码是没有调用 test 方法</span><br><span class="line">//	代码该为[self performSelector:@selector(test) withObject:self]; 打印结果为123</span><br><span class="line">// 因为</span><br><span class="line">performSelector withObject == [self test] == objcMessageSend(self,@selector(test))</span><br><span class="line"></span><br><span class="line">[self performSelector:@selector(test) withObject:self afterDelay:.0];这行代码执行到主线成会打印,是因为 performSelector withObject afterDelay 这方法会在当前的Runloop里面添加一个Timer,所以我们创建的子线程是没有Runloop的所以无法执行</span><br></pre></td></tr></table></figure>
<h5 id="修改上面的代码"><a href="#修改上面的代码" class="headerlink" title="修改上面的代码"></a>修改上面的代码</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">// 给当前子线程添加一个Runloop并且启动Runloop 会 执行afterDelay方法</span><br><span class="line">- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event &#123;</span><br><span class="line">    </span><br><span class="line">    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);</span><br><span class="line">    dispatch_async(queue, ^&#123;</span><br><span class="line">        NSLog(@&quot;任务1&quot;);</span><br><span class="line">        [self performSelector:@selector(test) withObject:self afterDelay:.0];</span><br><span class="line">        NSLog(@&quot;任务3&quot;);</span><br><span class="line">        </span><br><span class="line">        [[NSRunLoop currentRunLoop]addPort:[[NSPort alloc]init] forMode:NSDefaultRunLoopMode]; // 其实这句代码可以去掉,因为afterDelay:这方法底层已经有Runloop并且runloop中添加了Timer 只是没启动而已,所以直接写下一行代码就可以了</span><br><span class="line">        [[NSRunLoop currentRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)test&#123;</span><br><span class="line">    NSLog(@&quot;任务2&quot;);</span><br><span class="line">&#125;</span><br><span class="line">//	打印结果:  任务1 任务3 任务2</span><br></pre></td></tr></table></figure>
<h5 id="Runloop和线程相关的"><a href="#Runloop和线程相关的" class="headerlink" title="Runloop和线程相关的"></a>Runloop和线程相关的</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event &#123;</span><br><span class="line">    </span><br><span class="line">    NSThread *thread = [[NSThread alloc]initWithBlock:^&#123;</span><br><span class="line">        NSLog(@&quot;任务1&quot;);</span><br><span class="line">    &#125;];</span><br><span class="line">    [thread start];</span><br><span class="line"></span><br><span class="line">    [self performSelector:@selector(test) onThread:thread withObject:nil waitUntilDone:YES];</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)test&#123;</span><br><span class="line">    NSLog(@&quot;任务2&quot;);</span><br><span class="line">&#125;</span><br><span class="line">// 打印结果 任务1 打印之后会崩溃 因为performSelector onThread 调用时候 thread已经释放了</span><br><span class="line">//除非 开启runloop</span><br><span class="line">- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event &#123;</span><br><span class="line">    </span><br><span class="line">    NSThread *thread = [[NSThread alloc]initWithBlock:^&#123;</span><br><span class="line">        NSLog(@&quot;任务1&quot;);</span><br><span class="line">        [[NSRunLoop currentRunLoop]addPort:[[NSPort alloc]init] forMode:NSDefaultRunLoopMode];</span><br><span class="line">        [[NSRunLoop currentRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];</span><br><span class="line">    &#125;];</span><br><span class="line">    [thread start];</span><br><span class="line"></span><br><span class="line">    [self performSelector:@selector(test) onThread:thread withObject:nil waitUntilDone:YES];</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="GCD队列组Group"><a href="#GCD队列组Group" class="headerlink" title="GCD队列组Group"></a>GCD队列组Group</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">- (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(UIEvent *)event &#123;</span><br><span class="line"></span><br><span class="line">    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);</span><br><span class="line">    dispatch_group_t group = dispatch_group_create();</span><br><span class="line">    dispatch_group_async(group, queue, ^&#123;</span><br><span class="line">        NSLog(@&quot;任务1&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">    </span><br><span class="line">    dispatch_group_async(group, queue, ^&#123;</span><br><span class="line">        NSLog(@&quot;任务2&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">    </span><br><span class="line">    // group_notify是group 中添加的任务执行完之后才执行 group_notify</span><br><span class="line">    dispatch_group_notify(group, queue, ^&#123;</span><br><span class="line">        NSLog(@&quot;1和2执行完之后再执行任务3&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">    </span><br><span class="line">    // 或者更换队列也是可以的</span><br><span class="line">    dispatch_group_notify(group, dispatch_get_main_queue(), ^&#123;</span><br><span class="line">        NSLog(@&quot;1和2执行完之后再执行任务3&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">    //  也可以执行多个任务</span><br><span class="line">    dispatch_group_notify(group, queue, ^&#123;</span><br><span class="line">        NSLog(@&quot;1和2执行完之后再执行任务3 和 任务4&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="安全隐患线程锁"><a href="#安全隐患线程锁" class="headerlink" title="安全隐患线程锁"></a>安全隐患线程锁</h5><table>
<thead>
<tr>
<th style="text-align:center">方案</th>
<th style="text-align:center">头文件</th>
<th style="text-align:center">注意点</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">OSSpinLock</td>
<td style="text-align:center">#import &lt;libkern/OSAtomic.h&gt;</td>
<td style="text-align:center">自旋锁:一直在询问锁有没有被打开,一旦打开停止循环询问,一直占用着CPU,iOS 10弃用,可能出现优先级翻转问题,就是优先级低的线程正在执行任务,这时候优先级高的线程在等待解锁因为优先级高所以有可能优先级低的任务永远执行不完任务,</td>
</tr>
<tr>
<td style="text-align:center">os_unfair_lock</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">pthread_mutex</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">dispatch_semaphoer</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">dispatch_queue(DISPATCH_QUEUE_SERIAL)</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">NSLock</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">NSRecursiveLock</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">NSCondition</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">NSConditionLock</td>
<td style="text-align:center"></td>
</tr>
</tbody>
</table>
<h6 id="OSSpinLock"><a href="#OSSpinLock" class="headerlink" title="OSSpinLock"></a>OSSpinLock</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">#import &lt;libkern/OSAtomic.h&gt;</span><br><span class="line">@interface ViewController ()</span><br><span class="line"></span><br><span class="line">/***/</span><br><span class="line">@property(assign,nonatomic) NSInteger max;</span><br><span class="line"></span><br><span class="line">// 多个线程需要同一个锁</span><br><span class="line">@property(assign,nonatomic) OSSpinLock lock;</span><br><span class="line"></span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation ViewController</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    self.max = 20;</span><br><span class="line">    self.lock = OS_SPINLOCK_INIT;</span><br><span class="line">    [self test];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">- (void)test&#123;</span><br><span class="line">    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);</span><br><span class="line">    dispatch_async(queue, ^&#123;</span><br><span class="line">        for (int i = 0; i &lt; 5; i++) &#123;</span><br><span class="line">            [self execute];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">    dispatch_async(queue, ^&#123;</span><br><span class="line">        for (int i = 0; i &lt; 5; i++) &#123;</span><br><span class="line">            [self execute];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">    dispatch_async(queue, ^&#123;</span><br><span class="line">        for (int i = 0; i &lt; 5; i++) &#123;</span><br><span class="line">            [self execute];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)execute&#123;</span><br><span class="line">    OSSpinLockLock(&amp;_lock);</span><br><span class="line">    sleep(.1);</span><br><span class="line">    self.max--;</span><br><span class="line">    OSSpinLockUnlock(&amp;_lock);</span><br><span class="line">    NSLog(@&quot;%ld&quot;,self.max);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h6 id="跨方法"><a href="#跨方法" class="headerlink" title="跨方法"></a>跨方法</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">- (void)test2&#123;</span><br><span class="line">    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);</span><br><span class="line">    dispatch_async(queue, ^&#123;</span><br><span class="line">        for (int i = 0; i &lt; 5; i++) &#123;</span><br><span class="line">            [self execute1];    //减去 5</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">    dispatch_async(queue, ^&#123;</span><br><span class="line">        for (int i = 0; i &lt; 5; i++) &#123;</span><br><span class="line">            [self execute1];    //减去 5</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">    dispatch_async(queue, ^&#123;</span><br><span class="line">        for (int i = 0; i &lt; 5; i++) &#123;</span><br><span class="line">            [self execute2];   // 加5</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)execute1&#123;</span><br><span class="line">    OSSpinLockLock(&amp;_lock);</span><br><span class="line">    sleep(1);</span><br><span class="line">    self.max--;</span><br><span class="line">    OSSpinLockUnlock(&amp;_lock);</span><br><span class="line">    NSLog(@&quot;%ld&quot;,self.max);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)execute2&#123;</span><br><span class="line">    OSSpinLockLock(&amp;_lock);</span><br><span class="line">    sleep(1);</span><br><span class="line">    self.max++;</span><br><span class="line">    OSSpinLockUnlock(&amp;_lock);</span><br><span class="line">    NSLog(@&quot;%ld&quot;,self.max);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/11/14/键盘弹出/" rel="next" title="键盘弹出">
                <i class="fa fa-chevron-left"></i> 键盘弹出
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/19/tabBarItemClick/" rel="prev" title="tabBarItemClick">
                tabBarItemClick <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/10.png"
                alt="Erhqe" />
            
              <p class="site-author-name" itemprop="name">Erhqe</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">70</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">31</span>
                  <span class="site-state-item-name">categories</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">tags</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#iOS中的常见的多线程方案"><span class="nav-number">1.</span> <span class="nav-text">iOS中的常见的多线程方案</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#GCD同步异步函数队列"><span class="nav-number">1.1.</span> <span class="nav-text">GCD同步异步函数队列</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Swift"><span class="nav-number">1.2.</span> <span class="nav-text">Swift</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#GCD死锁"><span class="nav-number">1.3.</span> <span class="nav-text">GCD死锁</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#并发队列不同的方式创建是否是同一个"><span class="nav-number">1.4.</span> <span class="nav-text">并发队列不同的方式创建是否是同一个?</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#GCD和Runloop相关的问题"><span class="nav-number">1.5.</span> <span class="nav-text">GCD和Runloop相关的问题</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#修改上面的代码"><span class="nav-number">1.6.</span> <span class="nav-text">修改上面的代码</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Runloop和线程相关的"><span class="nav-number">1.7.</span> <span class="nav-text">Runloop和线程相关的</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#GCD队列组Group"><span class="nav-number">1.8.</span> <span class="nav-text">GCD队列组Group</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#安全隐患线程锁"><span class="nav-number">1.9.</span> <span class="nav-text">安全隐患线程锁</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#OSSpinLock"><span class="nav-number">1.9.1.</span> <span class="nav-text">OSSpinLock</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#跨方法"><span class="nav-number">1.9.2.</span> <span class="nav-text">跨方法</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Erhqe</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'TiAY2J24ECwQH9uLYsoJpgIK-gzGzoHsz',
        appKey: 'Y9PiVrPXVmfNsv4Aa6cPsADG',
        placeholder: 'Just go go',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

</body>
</html>
